package com.kcn.upload;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.commons.io.IOUtils;
import com.kcn.xml.Doc2XML;
import com.opensymphony.xwork2.ActionSupport;
public class UploadAction extends ActionSupport {
	// 必须的参数，参数名与表单名相同，如果表单名为多个上传文件，则必须为数组或List
	private File[] upload;
	// 必须的参数，格式：表单名+ContentType，表示上传文件类型
	private String[] uploadContentType;
	// 必须的参数，格式：表单名+FileName，表示上传的文件名
	private String[] uploadFileName;
	// 文件保存的位置
	private String savePath;
	Doc2XML d2x=new Doc2XML();

	public String upload() throws Exception {
		
		for (int i = 0; i < this.getUpload().length; i++) {
			FileInputStream in = new FileInputStream(this.getUpload()[i]);
			System.out.println(this.getSavePath()
					+ this.getUploadFileName()[i]);
			FileOutputStream out = new FileOutputStream(this.getSavePath()
					+ "\\" + this.getUploadFileName()[i]);
			// 将数据拷贝到上传目录，这里没有必要使用缓冲流，因为IOUtiles工具类已经使用了缓存
			IOUtils.copy(in, out);
			out.close();
			in.close();
		}
		System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaa");
		try {
			System.out.println("bbbbbbbbbbbbbbbbbbbbbbbbbbbb");
			d2x.BuildXMLDOC();
			System.out.println("ccccccccccccccccccccccccccc");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return SUCCESS;
	}

	public File[] getUpload() {
		return upload;
	}

	public void setUpload(File[] upload) {
		this.upload = upload;
	}

	public String[] getUploadContentType() {
		return uploadContentType;
	}

	public void setUploadContentType(String[] uploadContentType) {
		this.uploadContentType = uploadContentType;
	}

	public String[] getUploadFileName() {
		return uploadFileName;
	}

	public void setUploadFileName(String[] uploadFileName) {
		this.uploadFileName = uploadFileName;
	}

	public String getSavePath() {
		return savePath;
	}

	public void setSavePath(String savePath) {
		this.savePath = savePath;
	}

}
